package com.zjmzxfzhl.modules.flowable.controller;

import com.zjmzxfzhl.common.core.Result;
import com.zjmzxfzhl.modules.flowable.common.BaseFlowableController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.flowable.job.api.Job;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author 庄金明
 * @date 2020年3月24日
 */
@Api(tags = "流程定义定时任务")
@RestController
@RequestMapping("/flowable/processDefinitionJob")
public class ProcessDefinitionJobController extends BaseFlowableController {

    @ApiOperation(value = "流程定义定时任务分页查询")
    @GetMapping(value = "/list")
    public List<Job> list(@RequestParam String processDefinitionId) {
        return managementService.createTimerJobQuery().processDefinitionId(processDefinitionId).list();
    }

    @ApiOperation(value = "删除流程定义定时任务")
    @DeleteMapping(value = "/delete")
    @Transactional(rollbackFor = Exception.class)
    public Result deleteJob(@RequestParam String jobId) {
        managementService.deleteTimerJob(jobId);
        return Result.ok();
    }
}
